<template>
	<view class="">
		<view class="beijse">
			<view class="ffffff radius mainpadding">
				<view class="margin_top1 ershil xiaohei nofonweight textcenter">可用余额（元）</view>
				<view class="margin_top1 bigtext xiaohei fonweight textcenter" v-if="type==0">{{userInfo.money}}</view>
				<view class="margin_top1 bigtext xiaohei fonweight textcenter" v-if="type==1">{{dataAll.money}}</view>
				<view class="flexbetween margin_top"  v-if="type==0">
					<view class="wushi flexcenter" @click="jumper('/pages_mypage/huiyuankcz?type=0')">
						<view class="chonbtn">充值</view>
					</view>
					<view class="wushi flexcenter"  @click="jumper('/pages_mypage/tixian?type=1')">
						<view class="tixbtn">提现</view>
					</view>
				</view>
				<view class="flexcenter margin_top"  v-if="type==1">
					<view class="wushi flexcenter" @click="jumpurl('/pages_mypage/huiyuankcz?type=1&id=',listid)">
						<view class="chonbtn">充值</view>
					</view>
				</view>
			</view>
		</view>
		<view class="mainpadding2">
			<!--交易明细  -->
			<view class="mainpadding ffffff  radius">
				<view class="sanshier xiaohei fonweight">交易明细</view>
				<view class="flexcenter" v-if="!list.data.length">
					<view class="placeholderimage" style="margin-top: 100rpx;" ></view>
				</view>
				<view class="xiahuaxian flexbetween margin_top" v-for="item in list.data" :key="item.id">
					<view class="">
						<view class=" ershil xiaohei nofonweight ">{{item.memo}}</view>
						<view class="margin_top1 strongtext xiaohui nofonweight ">{{item.createtime_text}}</view>
					</view>
					<view class=" sanshier xiaohei fonweight ">{{item.money}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				userInfo:{},
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				listid:"",
				type:0,//0我的余额，1我的某一个会员卡的余额
				dataAll:{},
			}
		},
		onLoad(options) {
			if(options.type==1){//我的会员卡余额明细
				this.type = options.type
				this.listid = options.id
			}
		},
		onShow() {
			if(this.type==0){
				this.userinfomsg()
			}else if(this.type==1){
				this.getDetail()
			}
			this.init()
		},
		methods: {
			getDetail() {
				httpRequest.request("/api/user/userHycardDetail", 'GET', {
					id: this.listid
				}, false, false, true).then(res => {
					this.dataAll = res.data
				})
			},
			init(isPage, page) {
				let _this = this;
				let data = {
					page: page || 1,
					limit: _this.limit,
				}
				let url = '/api/user/getUserMoneyLog'
				if(this.type==1){//我的会员卡明细
					url="/api/user/userHycardMoneyLog"
					this.$set(data,"user_hycard_id",this.listid)
				}
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			userinfomsg() {
				httpRequest.request('/api/user/index', 'GET', {}).then(res => {
					this.userInfo = res.data
				})
			},
			jumper(url) {
				uni.navigateTo({
					url: url
				})
			},
			jumpurl(url,id) {
				uni.navigateTo({
					url: url+id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.wushi {
		width: 50%;
	}

	.tixbtn {
		width: 176rpx;
		height: 72rpx;
		background: #1BA95B;
		border-radius: 44rpx 44rpx 44rpx 44rpx;
		font-size: 28rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.chonbtn {
		width: 176rpx;
		height: 72rpx;
		background: #F76222;
		border-radius: 44rpx 44rpx 44rpx 44rpx;
		font-size: 28rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.beijse {
		padding: 30rpx;
		background: linear-gradient(180deg, #1BA95B 0%, #F9F9F9 100%);
	}

	page {
		background: #F9F9F9;
	}
</style>